package com.haonan.service.Impl;

import com.haonan.mapper.DeptMapper;
import com.haonan.pojo.entily.Dept;
import com.haonan.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    /**
     * 查询所有部门
     * @return
     */
    public List<Dept> findAll() {
        List<Dept> list = deptMapper.findAll();
        return list;
    }

    /**
     * 根据id删除部门
     * @param id
     */
    public void deleteById(Integer id) {
        deptMapper.deleteById(id);
    }

    /**
     * 添加部门
     * @param dept
     */
    public void save(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insert(dept);
    }

    //编辑部门    1.先查找部门，展示部门信息   2.在编辑
    public Dept findById(Integer id) {
        return deptMapper.findById(id);
    }

    /**
     * 修改部门信息
     * @param dept
     */
    public void update(Dept dept) {
       dept.setUpdateTime(LocalDateTime.now());
       deptMapper.update(dept);
    }
}
